$(function () {
    $("#maijia").click(function () {
        $.ajax({
            url:"getSeller.do",
            dataType:"json",
            success:function (data) {
                $("#div1").html("");
                $("#div1").append("<table id=td1>\n" +
                    "                <tr>\n" +
                    "                    <td>客户ID</td>\n" +
                    "                    <td>客户名称</td>\n" +
                    "                    <td>客户手机</td>\n" +
                    "                    <td>客户电话</td>\n" +
                    "                </tr>")
                for (let i = 0; i < data.length; i++) {
                    $("#td1").append("<tr onclick='xiuGai(this)'><td>"+data[i].custID+"</td><td>"+data[i].custName+"</td><td>"+data[i].custMobile+"</td><td>"+data[i].custTel+"</td></tr>")
                }
                $("#div1").append("</table>")
            }
        })
    })
    $("#maijia1").click(function () {
        $.ajax({
            url:"getBuyer.do",
            dataType:"json",
            success:function (data) {
                $("#div2").html("");
                $("#div2").append("<table id=\"td2\">\n" +
                    "                <tr>\n" +
                    "                    <td>客户ID</td>\n" +
                    "                    <td>客户名称</td>\n" +
                    "                    <td>客户手机</td>\n" +
                    "                    <td>客户电话</td>\n" +
                    "                </tr>")
                for (let i = 0; i < data.length; i++) {
                    $("#td2").append("<tr onclick='xiuGai2(this)'><td>"+data[i].custID+"</td><td>"+data[i].custName+"</td><td>"+data[i].custMobile+"</td><td>"+data[i].custTel+"</td></tr>")
                }
                $("#div2").append("</table>")
            }
        })
    })
    $("#cucun").blur(function () {
        if($("#qita").val()==0){
            alert("其他费用不能为空")
        }else{
            var qita = parseInt($("#qita").val());
            var cucun = parseInt(this.value);
            var heji = qita+cucun
            $("#heji").val(heji);
            $("#heji1").val(heji);
            $("#shishou").val(heji);
            $("#shishou1").val(heji);
        }
    })
    $("#qita").blur(function () {
        if($("#cucun").val()==0){
            alert("储存费用不能为空")
        }else{
            var qita = parseInt(this.value);
            var cucun = parseInt($("#cucun").val());
            var heji = qita+cucun
            $("#heji").val(heji);
            $("#heji1").val(heji);
            $("#shishou").val(heji);
            $("#shishou1").val(heji);
        }
    })
    $("#form1").submit(function () {
        var date1 = $("#date1").val();
        var date2 = $("#date2").val();
        if (date1 > date2) {
            alert('开始日期不能大于结束日期');
            return false;
        } else {
            alert('合格');
            return true;
        }
    })
})
function xiuGai(div1) {
    //获取得到需要的值
    var want = div1.cells[0].innerHTML + "-" + div1.cells[1].innerHTML;
    //2 输入框的内容是你点击的div的内容
    $("#maijia").val(want);
    //1 让下方div内容清空
    $("#div1").html("");

}
function xiuGai2(div1) {
    //获取得到需要的值
    var want = div1.cells[0].innerHTML + "-" + div1.cells[1].innerHTML;
    //2 输入框的内容是你点击的div的内容
    $("#maijia1").val(want);
    //1 让下方div内容清空
    $("#div2").html("");

}
function startguohu() {
    let flag=0
    let detailsid = document.getElementsByName("details");
    let detailsGoodNum = document.getElementsByName("detailsGoodsNum");
    let danxuantd = document.getElementsByName("Checkbox");
    for( let i=0;i<danxuantd.length;i++){
        if(danxuantd[i].checked==true){
            window.location = "getGuohuDan.do?detailsid="+detailsid[i].innerHTML+"&&detailsNum="+detailsGoodNum[i].innerHTML;
            flag=1
            break
        }
    }
    if(!flag){
        alert("必须选择一个")
    }
}